package com.my.jli.Service.impl;

import com.my.jli.Service.MyFileService;
import com.my.jli.dao.MyFileRepository;
import com.my.jli.entity.MyFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * @ClassName MyFileServiceImpl
 * @Description
 * @Author MaYu
 * @Date 2022/3/26 9:31
 * @Version 1.0
 **/
@Service
public class MyFileServiceImpl implements MyFileService {

    private MyFileRepository myFileRepository;
    @Autowired
    public void setMyFileRepository(MyFileRepository myFileRepository) {
        this.myFileRepository = myFileRepository;
    }

    @Override
    @Transactional(readOnly = true)
    public List<MyFile> findAll() {
        return myFileRepository.findAll();
    }

    @Override
    @Transactional(readOnly = true)
    public Page<MyFile> findAll(Pageable pageable) {
        return myFileRepository.findAll(pageable);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public MyFile addMyFile(MyFile myFile) {
        return myFileRepository.save(myFile);
    }

    @Override
    @Transactional(readOnly = true)
    public List<MyFile> findByJurisdiction(int jurisdiction) {
        return myFileRepository.findByJurisdiction(jurisdiction);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<MyFile> findByJurisdiction(int jurisdiction, Pageable pageable) {
        return myFileRepository.findByJurisdiction(jurisdiction, pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<MyFile> findAll(Example<MyFile> myFileExample, Pageable pageable) {
        return myFileRepository.findAll(myFileExample, pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Set<String> findAllType() {
        return myFileRepository.findAllType();
    }

    @Override
    @Transactional(readOnly = true)
    public MyFile getById(Integer id) {
        Optional<MyFile> optionalMyFile = myFileRepository.findById(id);
        //判断有无记录
        return optionalMyFile.orElse(null);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteById(Integer id) {
        myFileRepository.deleteById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public MyFile update(MyFile myFile) {
        return myFileRepository.save(myFile);
    }


}
